package com.androidcourse.changeandget;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.androidcourse.changeandget.Database.DBHelper;
import com.androidcourse.changeandget.User.Good;
import com.androidcourse.changeandget.User.User;

public class exchange extends AppCompatActivity {
    private String SID;
    private String Password;
    private TextView stu_id;
    private TextView Sname;
    private TextView Sestate;
    private User person;
    DBHelper mSQlite;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exchange);
        TextView Name=(TextView)findViewById(R.id.name1);
        TextView Hood=(TextView)findViewById(R.id.hood1);
        TextView Time=(TextView)findViewById(R.id.time1);
        TextView Describe=(TextView)findViewById(R.id.describe1);
        TextView WantGoods=(TextView)findViewById(R.id.wantgoods1);
        ImageView photo=(ImageView)findViewById(R.id.goods);
        Button Back=(Button) findViewById(R.id.back);
        Button Agree=(Button)findViewById(R.id.agree);
        mSQlite = new DBHelper(exchange.this);

        Intent intent = getIntent();

        Bundle bundle = intent.getExtras();
        assert bundle != null;
        String Gname=bundle.getString("Gname");
        String GID=bundle.getString("GID");
        String SID=bundle.getString("SID");
        //获取从homepage中传入的GID用于搜寻

        Toast.makeText(this,Gname,Toast.LENGTH_SHORT).show();
        DBHelper mSQlite = new DBHelper(exchange.this);
        Good[] goods=mSQlite.getonedata(GID);


        int gid=0;
        Name.setText(goods[gid].getGname());
        Hood.setText(goods[gid].getHood());
        Time.setText(goods[gid].getTime());
        Describe.setText(goods[gid].getDGood());
        WantGoods.setText(goods[gid].getEGood());
        Bitmap bitmap= BitmapFactory.decodeByteArray(goods[gid].getImage(),0,goods[gid].getImage().length);
        photo.setImageBitmap(bitmap);
        Back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                finish();
            }
        });
        Agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            goods[gid].setChange(true);
            mSQlite.upgrade(GID);
            }
        });
    }
}